/*************************************************************************
	> File Name: premire.c
	> Author: Angel Criss
	> Mail: abbytsing@gmail.com 
	> Created Time: 三  7/16 20:30:15 2014
 ************************************************************************/

#include<stdio.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
    if(argc<2)
    {
        printf("%s number\n",argv[0]);
        exit(EXIT_FAILURE);
    }

    int i,j,flag,sum=0,sum1=3;
    int arg=atoi(argv[1]);

    if(arg<=3)
    {
        switch(arg){
            case 0:
                printf("\e[45mwrong number\e[0m\n");
                exit(EXIT_FAILURE);
            case 1:
                printf("\t\e[36m %d \e[0m is prime number\n",arg);
                sum+=1;
                break;
            case 2:
                printf("\t\e[36m %d \e[0m is prime number\n",arg-1);
                printf("\t\e[36m %d \e[0m is prime number\n",arg);
                sum+=2;
                break;
            case 3:
                printf("\t\e[36m %d \e[0m is prime number\n",arg-2);
                printf("\t\e[36m %d \e[0m is prime number\n",arg-1);
                printf("\t\e[36m %d \e[0m is prime number\n",arg);
                sum+=3;
                break;
            default:
                break;
        }
    }
    else{
        printf("\t\e[36m 1 \e[0m is prime number\n");
        printf("\t\e[36m 2 \e[0m is prime number\n");
        printf("\t\e[36m 3 \e[0m is prime number\n");

        for(i=2;i<=arg;i++)
        {
            for(j=2;j<=i/2;j++)
            {
                if(i%j==0)
                {
                    flag=0;
                    break;
                }
                else
                    flag=1;
            }
            if(flag==1)
            {
                printf("\t\e[36m %d \e[0m is prime number\n",i);
                sum1+=1;
            }

        }
    }
    if(arg<=3)
    printf("there are \e[32m %d \e[0m prime numbers within \e[34m%s\e[0m\n",sum,argv[1]);
    else
    {
        printf("there are \e[32m %d \e[0m prime numbers within \e[34m%s\e[0m\n",sum1,argv[1]);
    }

}
